﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;

namespace QA_System
{
    public class NN_EcllipsisDiscover:IDisCoverInterface
    {
        static XMLVerbConnection verbconnect = new XMLVerbConnection();

        static XMLNounConnection nounconnect = new XMLNounConnection();

        private string filename;
        static string xmlDatabasePath = QA_System.Properties.Settings.Default.xmlDatabasePath;
        

        public NN_EcllipsisDiscover()
        {
            filename = xmlDatabasePath + "VerbXMLdatabase.xml";
            
        }

        public NN_EcllipsisDiscover(string datafilename)
        {
            filename = datafilename;
        }

        public string DataFilename
        {
            get { return filename; }

            set { filename = value; }
        }

        #region IDisCoverInterface Members

        public bool IsOccup(SentenceStruct sen)
        {
            try
            {
                bool result = false;
                int[] allVerbposition = sen.GetAllVerbPosition();
                if (allVerbposition.Length == 0)
                {
                    if ((sen.SentenceLength - 1 - sen.GetNounsPosition().Length) == 0) result = true;
                    //hỏi thời gian khi nào, lúc nào. Trả lời: 2 giờ
                    else if (sen.StrSentencePos.Contains("M Nu")) result = true;
                    //TH: thế còn ngày sinh, quốc tịch
                    else if (sen.StrSentencePos.Contains("- R N")) result = true;
                    else if (sen.StrSentencePos.Contains("- C N")) result = true;
                    else
                    {
                        if ((sen.SentenceLength <= 4) && (sen.GetVerbPosition(0, sen.SentenceLength - 1) == -1))
                        {
                            if (!sen.StrSentencePos.Contains("N R A")) result = true;
                        }

                    }
                }
                else
                {
                    if ((allVerbposition.Length >= 1) && sen.GetNounsPosition2(0,allVerbposition[0])==-1)
                    {
                        result= true;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public string TypeOccup(SentenceStruct refsen, SentenceStruct sen)
        {
            try
            {
                string result="Other";
                if (sen[sen.SentenceLength - 1].Equals(".") && (refsen[refsen.SentenceLength - 1].Equals("."))) result = "Same";
                else
                {
                    if (sen[sen.SentenceLength - 1].Equals("?") && (refsen[refsen.SentenceLength - 1].Equals("?"))) result = "Same";
                }
                return result;
            }
            catch (XmlException ex)
            {
                throw ex;
            }
        }


        #endregion

        
    }

    public class VP_EcllipsisDiscover : IDisCoverInterface
    {
        static XMLVerbConnection verbconnect = new XMLVerbConnection();

        static XMLNounConnection nounconnect = new XMLNounConnection();

        private string filename;
        static string xmlDatabasePath = QA_System.Properties.Settings.Default.xmlDatabasePath;


        public VP_EcllipsisDiscover()
        {
            filename = xmlDatabasePath + "VerbXMLdatabase.xml";

        }

        public VP_EcllipsisDiscover(string datafilename)
        {
            filename = datafilename;
        }

        public string DataFilename
        {
            get { return filename; }

            set { filename = value; }
        }

        #region IDisCoverInterface Members

        public bool IsOccup(SentenceStruct sen)
        {
            try
            {
                bool result = false;
                string strPreverb = "được,do,bởi,bị";
                     int[] verbindex = sen.GetAllVerbPosition();
                     int i = 0;
                     if (sen.SentenceLength < 20)
                     {                   
                         while (i < verbindex.Length)
                         {
                             if (!(sen[verbindex[i] - 1].Pos.Equals("R") && strPreverb.Contains(sen[verbindex[i] - 1].Word))&&!sen[verbindex[i]-1].Pos.Equals("V"))
                             {
                                 string SubjectType = verbconnect.GetTypeofSubject(sen[verbindex[i]], filename);
                                 string ObjectType = verbconnect.GetTypeofObject(sen[verbindex[i]], filename);
                                 //Vinh sua lai: bo doan (verbindex[i] == sen.SentenceLength - 2) (8/4)
                                 if ( (sen[verbindex[i] + 1].Word.ToLower().Equals("đấy")) || (sen[verbindex[i] + 1].Word.ToLower().Equals("thế")) || (sen[verbindex[i] + 1].Word.ToLower().Equals("vậy"))
                                      || (sen[verbindex[i] + 2].Word.ToLower().Equals("đấy")) || (sen[verbindex[i] + 2].Word.ToLower().Equals("thế")) || (sen[verbindex[i] + 2].Word.ToLower().Equals("vậy"))
                                      || (sen[verbindex[i] + 1].Word.ToLower().Equals("như thế")) || (sen[verbindex[i] + 2].Word.ToLower().Equals("như thế"))
                                      || (sen[verbindex[i] + 1].Word.ToLower().Equals("như vậy")) || (sen[verbindex[i] + 2].Word.ToLower().Equals("như vậy")))
                                 {
                                     result = true;
                                 }
                                 //Vinh: bỏ đoạn dưới
                                 /*
                                 else
                                 {
                                     WordStruct suNoun = sen.GetSubjectofVerb(sen[verbindex[i]]);
                                     if (suNoun != null)
                                     {
                                         if (!string.IsNullOrEmpty(nounconnect.GetWordType(suNoun, "")))
                                         {
                                             if (!SubjectType.Contains(nounconnect.GetWordType(suNoun, ""))&&(sen[verbindex[i]].Word!="là")) result = true;
                                             else
                                             {
                                                 WordStruct obNoun = sen.GetTObjectofVerb(sen[verbindex[i]]);
                                                 if (null != obNoun)
                                                 {
                                                     if (ObjectType!="" && (!ObjectType.Contains(nounconnect.GetWordType(obNoun, "")))) result = true;
                                                 }
                                                 //Vinh: bỏ đoạn dưới
                                                 else
                                                 {
                                                     if (!string.IsNullOrEmpty(ObjectType) && (sen[verbindex[i]].Word != "là")) result = true;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                  * */
                             }
                             i++;
                         }
                     }
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public string TypeOccup(SentenceStruct refsen, SentenceStruct sen)
        {
            try
            {
                string result = "Other";
                if (sen[sen.SentenceLength - 1].Equals(".") && (refsen[refsen.SentenceLength - 1].Equals("."))) result = "Same";
                else
                {
                    if (sen[sen.SentenceLength - 1].Equals("?") && (refsen[refsen.SentenceLength - 1].Equals("?"))) result = "Same";
                }
                return result;
            }
            catch (XmlException ex)
            {
                throw ex;
            }
        }


        #endregion


    }
}
